package com.iTextDemo;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class CreateImage {
    public static void main(String[] args) throws URISyntaxException, IOException, DocumentException {
        Path path = Paths.get("C:\\Users\\wy\\Desktop\\1.png");
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\wy\\Desktop\\1\\iTextImageExample2.pdf"));
        document.open();
        Image img = Image.getInstance(path.toAbsolutePath().toString());
        document.add(img);
        document.close();
    }
}
